package listener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
@WebListener
public class OnlineListener implements HttpSessionListener {
    public void sessionCreated(HttpSessionEvent se)  { 
    	Object o = se.getSession().getServletContext().getAttribute("onLineNum");
    	if(o==null) {
    		se.getSession().getServletContext().setAttribute("onLineNum", 1);
    	} else {
    		int onLineNum = (int) o;
    		se.getSession().getServletContext().setAttribute("onLineNum", onLineNum + 1);
    	}
    }
    public void sessionDestroyed(HttpSessionEvent se)  { 
    	int onLineNum = (int)se.getSession().getServletContext().getAttribute("onLineNum");
    	se.getSession().getServletContext().setAttribute("onLineNum", onLineNum - 1);
    }
}
